package sz.szsmk.citizencard.ui.newversion.activity;


import android.os.Bundle;
import androidx.annotation.Nullable;

import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.chenenyu.router.annotation.Route;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.mvp.MyCouponMvpView;
import sz.szsmk.citizencard.model.network.bean.response.CouponListBean;
import sz.szsmk.citizencard.ui.dzsmkavtivity.AppBaseActivity;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.JumpUtils;

/**
 * Created by hyt on 2019/4/28.
 */
@Route("myCoupon")
public class MyCouponActivity extends AppBaseActivity implements MyCouponMvpView, View.OnClickListener {

    TextView tv_wenhua;
    TextView tv_tiyu;
    TextView tv_lvyou;
    TextView tv_shangcheng;


    TextView setting_title;
    CouponListBean couponListBean;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getComponent().inject(this);
        setContentView(R.layout.mycoupon_activity);

        tv_wenhua = findViewById(R.id.tv_wenhua);
        tv_tiyu = findViewById(R.id.tv_tiyu);
        tv_lvyou = findViewById(R.id.tv_lvyou);
        tv_shangcheng = findViewById(R.id.tv_shangcheng);

        findViewById(R.id.ib_wenhua).setOnClickListener(this);
        findViewById(R.id.ib_tiyu).setOnClickListener(this);
        findViewById(R.id.ib_lvyou).setOnClickListener(this);
        findViewById(R.id.ib_shangcheng).setOnClickListener(this);


        setting_title = findViewById(R.id.setting_title);


        setting_title.setText("我的优惠券");

        couponListBean = (CouponListBean) getIntent().getExtras().getSerializable("couponListBean");

        //type返回含义（1 旅游，2 商城，3 文化消费，4 场馆预定）
        if(couponListBean!=null){
            for(int i=0;i<couponListBean.getData().size();i++){
                CouponListBean.CouponBean couponBeanTemp = couponListBean.getData().get(i);
                Log.d("clark",couponBeanTemp.getType());
                switch (Integer.valueOf(couponBeanTemp.getType())){
                    case 1:
                        tv_lvyou.setText("旅游("+couponBeanTemp.getUsedCount()+")");
                        break;
                    case 2:
                        tv_shangcheng.setText("商城("+couponBeanTemp.getUsedCount()+")");
                        break;
                    case 3:
                        tv_wenhua.setText("文化("+couponBeanTemp.getUsedCount()+")");
                        break;
                    case 4:
                        tv_tiyu.setText("体育("+couponBeanTemp.getUsedCount()+")");
                        break;
                }

            }

        }

    }

    public void onMyCoupon(View v){
        String access_token = ACache.get(mContext).getAsString("access_token");
        int id = v.getId();
        if (id == R.id.ib_wenhua) {//文化
            if (access_token == null) {
                toLogin();
            } else {
                String mextend = ACache.get(DaggerApplication.getIns()).getAsString("mextend");
                Bundle bundle = new Bundle();
                String test = "https://whywechat.suzhou.gov.cn/quan" + "?" + Constant.EXTENT;
                bundle.putString("url", test);
                bundle.putString(Constant.TITLE, "");
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
            }
        } else if (id == R.id.ib_tiyu) {//体育
            if (access_token == null) {
                toLogin();
            } else {
                String mextend = ACache.get(DaggerApplication.getIns()).getAsString("mextend");
                Bundle bundle = new Bundle();
                bundle.putString("url", "http://tyhm.szsmk.com/portal/my_hxcode.html?" + ACache.get(DaggerApplication.getIns()).getAsString("extend"));
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
            }
        } else if (id == R.id.ib_lvyou) {//旅游
            if (access_token == null) {
                toLogin();
            } else {
                Bundle bundle = new Bundle();
                bundle.putString(Constant.TITLE, "优惠券");
                L.e(Constant.TAG, "access_token====" + access_token);
                bundle.putString("url", "http://newapp2.szsmk.com/app-front-end/#/mine/coupons?access_token=" + access_token + "&ntype=" + "1");
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);

//
            }
        } else if (id == R.id.ib_shangcheng) {//商城
            if (access_token == null) {
                toLogin();
            } else {
                Bundle bundle = new Bundle();
                L.e(Constant.TAG, "access_token====" + access_token);
                bundle.putString("url", "http://newapp2.szsmk.com/app-front-end/#/mine/coupons?access_token=" + access_token + "&ntype=" + "2");
                bundle.putString(Constant.TITLE, "");
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
            }
        }


    }

    public void toLogin() {
        JumpUtils.jump(mContext, "login", 0);
    }


    @Override
    protected CharSequence getTopTitle() {
        return null;
    }

    @Override
    public void onClick(View v) {
        onMyCoupon(v);
    }
}
